package com.wealth.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.wealth.system.entity.User;
import com.wealth.system.repository.UserDao;
import com.wealth.system.service.IUserService;

import iaas.service.impl.BaseServiceImpl;

@Component
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService{
	
	@Autowired
	private UserDao userDao;

	/**
	 * 查询用户,通过登陆名
	 */
	@Override
	public User findUserByUsername(String username) {
		return userDao.findByUsername(username);
	}
	
	/**  查询企业管理员 */
	@Override
	public User findCorpAmin(Long corpid) throws Exception  {
		return userDao.findCorpAmin(corpid);
	}
	
	
	/**
	 * 用户名是否唯一
	 */
	@Override
	public boolean unique(String username) throws Exception {
		User user = userDao.findByUsername(username);
		return (user==null)?true:false;
	}
	
	/**
	 * 修改密码
	 */
	@Override
	@Transactional(readOnly=false)
	public void updatePassword(User user) throws Exception {
		User temp = userDao.findOne(user.getId());
		temp.setPassword(user.getPassword());
		userDao.save(temp);
	}

	@Override
	public List<User> getUserByCorpIdAndStatus(Long corpid, int value) {
		return userDao.getUserByCorpIdAndStatus(corpid, value);
	}
}
